package com.atomway.consumer.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.atomway.consumer.feign.SidecarFeign;
import com.atomway.consumer.feign.UserFeignClient;
import com.atomway.consumer.user.entity.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;

@RestController
@RequestMapping("/consumer")
public class MovieController {

	@Autowired
	private UserFeignClient userFeignClient;
	
	@Autowired
	private SidecarFeign sidecarFeign;
	
//	@HystrixCommand(fallbackMethod="findByIdFallback",
//		commandProperties = {
//				@HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE" )
//		}
//	)
	@GetMapping("/user/{id}")
	public User findById(@PathVariable Long id) {
		return userFeignClient.findById(id);
	}
	
	@GetMapping("/sidecar")
	public String getSidecarIndex() {
		return sidecarFeign.getIndex();
	}
	
	@GetMapping("/sidecar/health")
	public String getSidecarHealth() {
		return sidecarFeign.getHealth();
	}
//	private User findByIdFallback(Long id) {
//		User user = new User();
//		user.setId(0l);
//		return user;
//	}
}
